//
//  LDMyResumeCellEduInAll.swift
//  DingDongZP
//
//  Created by LeMac on 16/12/27.
//  Copyright © 2016年 51ledian.com. All rights reserved.
//

import UIKit

class LDMyResumeCellEduInAll: LDMyResumeBaseCellInAll {

    
//    var model = myResumeCellExperienceModel()
    lazy var voiceBtn:LDMyResumeBaseVoiceBtn = LDMyResumeBaseVoiceBtn()
    private var rowsViewTag = 2222
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupView()
    }
    var vocieBtnClosure:((AnyObject)->())?
    
    override func updateView() {
        
        
        
        for item in bgView!.subviews {
            
            if item is UIButton == false {
                
                item.removeFromSuperview()
            }
        }
        
        addSubview(voiceBtn)
        addSubview(noticeLab)
        for (i,_) in model!.eduexperience!.enumerate() {
            
            
            let newRowV =  LDMyResumeCellEduInAll_Row()
            newRowV.tag = rowsViewTag + i
            bgView!.addSubview(newRowV)
            
            guard let rowModel = model?.eduexperience[i] else { return }
            newRowV.model = rowModel
        }
        
        
        for (i,_) in model!.eduexperience!.enumerate() {
            
            
            let views = viewWithTag(rowsViewTag+i) as! LDMyResumeCellEduInAll_Row
            let attrH =  90
            
            if i < 1 {
                
                views.snp_makeConstraints(closure: { (make) in
                    
                    make.top.equalTo(bgView!.snp_top).offset(LDMargin_V*3)
                    make.left.equalTo(LDMargin_V*3)
                    make.right.equalTo(-LDMargin_V*3)
                    make.height.equalTo(attrH)
                })
                
            } else {
                
                let preView = viewWithTag(rowsViewTag+i-1) as! LDMyResumeCellEduInAll_Row
                views.snp_makeConstraints(closure: { (make) in
                    make.top.equalTo(preView.snp_bottom).offset(LDMargin_V)
                    make.left.equalTo(LDMargin_V*3)
                    make.right.equalTo(-LDMargin_V*3)
                    make.height.equalTo(attrH)
                })
            }
            
            if i == model!.eduexperience.count - 1 {
                
                let lineH = UIView()
                lineH.backgroundColor = LDLineColorLightGray
                bgView!.addSubview(lineH)
                lineH.snp_makeConstraints { (make) in
                    
                    make.top.equalTo(views.snp_bottom)
                    make.centerX.equalTo(views.dotView!)
                    make.bottom.equalTo(0)
                    make.width.equalTo(0.5)
                    
                }
            }
            
        }
        
        voiceBtn.snp_makeConstraints { (make) in
            
            make.left.equalTo(LDMargin_V*7)
            make.right.equalTo(-80)
            make.height.equalTo(28)
            make.bottom.equalTo(-LDMargin_V*2)
        }
        
        noticeLab.snp_makeConstraints { (make) in
            
            make.left.equalTo(85)
            make.centerY.equalTo(voiceBtn)
            make.height.equalTo(20)
        }
        
        voiceBtn.voiceBtn!.bk_whenTapped { [weak self] in
            
            if self?.vocieBtnClosure != nil {
                
                self?.vocieBtnClosure!(self!)
            }
        }
        
        if model?.audioeduexperience_isset == "1" {
            
            voiceBtn.voiceBtn?.timeLab?.text = String(format: "%@'",model?.audioeduexperience_duration ?? "0")
            noticeLab.hidden = true
            
        } else {
            
            voiceBtn.voiceBtn?.hidden = true
            noticeLab.hidden = false
        }
        
        
         bgView?.bringSubviewToFront(editBtn!)
        
    }
    
    override func getCellHeight(model: DDMyResumeModel) -> CGFloat {
        
        let rowCount = model.eduexperience.count
        
        let allH = rowCount * 90 + 65 + 40
        
        return CGFloat(allH)
        
    }
    
    func setupView() {
        
//        let rowsView = LDMyResumeCellEduInAll_Row()
        
//        bgView!.addSubview(rowsView)
        
        title = "教育经历"
//        bgView!.addSubview(voiceBtn)
        
//        rowsView.snp_makeConstraints(closure: { (make) in
//            
//            make.top.equalTo(LDMargin_V*4)
//            make.left.equalTo(LDMargin_V*3)
//            make.right.equalTo(-LDMargin_V*3)
//            
//        })
//        
//        voiceBtn.snp_makeConstraints { (make) in
//            
//            make.left.equalTo(LDMargin_V*5)
//            make.right.equalTo(-LDMargin_V*3)
//            make.height.equalTo(28)
//            make.bottom.equalTo(-LDMargin_V*4)
//        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    

}
